/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * ElementPanel.java
 *
 * Created on 13.08.2010, 17:17:15
 */

package de.jmda.mview.typeshape;

import javax.lang.model.element.AnnotationMirror;
import javax.lang.model.element.Element;
import javax.lang.model.element.ExecutableElement;
import javax.lang.model.element.VariableElement;
import javax.swing.JPanel;


/**
 *
 */
public class ElementPanel<T extends Element>
    extends JPanel
{
	/**
   * 
   */
  private static final long serialVersionUID = 1L;
	protected T element;
	protected DisplayOptionsModelUtil displayOptionsModelUtil;
	protected ElementLabel<T> elementLabel;
//	protected List<ElementLabel<T>> annotationElementLabels =
//			new LinkedList<ElementLabel<T>>();

	/** Creates new form ElementPanel */
	public ElementPanel(
			T element,
			DisplayOptionsModelUtil displayOptionsModelUtil)
	{
		super();
		this.element = element;
		this.displayOptionsModelUtil = displayOptionsModelUtil;
		elementLabel = new ElementLabel<T>(element, displayOptionsModelUtil);
		initComponents();
		add(elementLabel, 0);
		showElementAnnotationLabels();
	}
	
	private void showElementAnnotationLabels()
	{
		if (element instanceof VariableElement)
		{
			if (displayOptionsModelUtil.displayFieldAnnotations())
			{
				for (AnnotationMirror annotationMirror : element.getAnnotationMirrors())
				{
					showElementAnnotationLabel(annotationMirror);
				}
			}
		}
		else if (element instanceof ExecutableElement)
		{
			if (displayOptionsModelUtil.displayMethodAnnotations())
			{
				for (AnnotationMirror annotationMirror : element.getAnnotationMirrors())
				{
					showElementAnnotationLabel(annotationMirror);
				}
			}
		}
	}
	
	private void showElementAnnotationLabel(AnnotationMirror annotationMirror)
  {
		ElementLabel<T> elementLabel =
				new ElementLabel<T>(
						(T) annotationMirror.getAnnotationType().asElement(),
						displayOptionsModelUtil);
//		annotationElementLabels.add(elementLabel);
		add(elementLabel, 0);
  }

	/**
	 * TODO: unexpected calls, something about CellRenderer?
	 *
	 * @see java.awt.Component#toString()
	 */
	public String toString()
	{
//		initialise();
		System.out.println("unexpected call to element " + element);
		return element.asType().toString();
	}

	/** This method is called from within the constructor to
	 * initialize the form.
	 * WARNING: Do NOT modify this code. The content of this method is
	 * always regenerated by the Form Editor.
	 */
  // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
  private void initComponents() {

    setLayout(new javax.swing.BoxLayout(this, javax.swing.BoxLayout.Y_AXIS));
  }// </editor-fold>//GEN-END:initComponents

  // Variables declaration - do not modify//GEN-BEGIN:variables
  // End of variables declaration//GEN-END:variables

}